/*     */ package com.zimbra.qa.unittest.server;
/*     */ 
/*     */ import com.zimbra.client.ZMailbox;
/*     */ import com.zimbra.client.ZMessage;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.db.DbOutOfOffice;
/*     */ import com.zimbra.cs.db.DbPool;
/*     */ import com.zimbra.cs.db.DbPool.DbConnection;
/*     */ import com.zimbra.cs.ldap.LdapUtil;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.qa.unittest.TestUtil;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestNotificationServer
/*     */   extends TestCase
/*     */ {
/*  44 */   private static String RECIPIENT_NAME = "user1";
/*  45 */   private static String SENDER_NAME = "user2";
/*     */   
/*  47 */   private static String[] ALL_TEST_USERS = { "user1", "user2" };
/*     */   
/*  49 */   private static String NAME_PREFIX = TestNotificationServer.class.getSimpleName();
/*     */   private boolean originalReplyEnabled;
/*     */   private String originalReply;
/*     */   private boolean originalNotificationEnabled;
/*     */   private String originalNotificationAddress;
/*     */   private String originalNotificationSubject;
/*     */   private String originalNotificationBody;
/*     */   private String[] originalInterceptAddresses;
/*     */   private String originalInterceptSendHeadersOnly;
/*     */   private String originalSaveToSent;
/*     */   private String originalMailForwardingAddress;
/*     */   private boolean originalLocalDeliveryDisabled;
/*     */   private boolean isServerTest;
/*     */   
/*     */   protected void setUp()
/*     */     throws Exception
/*     */   {
/*  66 */     super.setUp();
/*  67 */     cleanUp();
/*     */     
/*  69 */     Account account = TestUtil.getAccount(RECIPIENT_NAME);
/*  70 */     this.originalReplyEnabled = account.getBooleanAttr("zimbraPrefOutOfOfficeReplyEnabled", false);
/*  71 */     this.originalReply = account.getAttr("zimbraPrefOutOfOfficeReply", "");
/*  72 */     this.originalNotificationEnabled = account.getBooleanAttr("zimbraPrefNewMailNotificationEnabled", false);
/*  73 */     this.originalNotificationAddress = account.getAttr("zimbraPrefNewMailNotificationAddress", "");
/*  74 */     this.originalNotificationSubject = account.getAttr("zimbraNewMailNotificationSubject", "");
/*  75 */     this.originalNotificationBody = account.getAttr("zimbraNewMailNotificationBody", "");
/*  76 */     this.originalInterceptAddresses = account.getMultiAttr("zimbraInterceptAddress");
/*  77 */     this.originalInterceptSendHeadersOnly = account.getAttr("zimbraInterceptSendHeadersOnly", "");
/*  78 */     this.originalSaveToSent = account.getAttr("zimbraPrefSaveToSent", "");
/*  79 */     this.originalMailForwardingAddress = account.getAttr("zimbraPrefMailForwardingAddress", "");
/*  80 */     this.originalLocalDeliveryDisabled = account.getBooleanAttr("zimbraPrefMailLocalDeliveryDisabled", false);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void testUtf8()
/*     */     throws Exception
/*     */   {
/*  91 */     this.isServerTest = true;
/*     */     
/*  93 */     String NEW_MAIL_SUBJECT = NAME_PREFIX + " Крокодил";
/*     */     
/*  95 */     String NEW_MAIL_BODY = NAME_PREFIX + " Черепаха";
/*     */     
/*  97 */     String OUT_OF_OFFICE_SUBJECT = NAME_PREFIX + " Обезьяна";
/*     */     
/*  99 */     String OUT_OF_OFFICE_BODY = NAME_PREFIX + " Жираф";
/*     */     
/*     */ 
/*     */ 
/* 103 */     Account account = TestUtil.getAccount(RECIPIENT_NAME);
/* 104 */     Map<String, Object> attrs = new HashMap();
/* 105 */     attrs.put("zimbraPrefOutOfOfficeReplyEnabled", "TRUE");
/* 106 */     attrs.put("zimbraPrefOutOfOfficeReply", OUT_OF_OFFICE_BODY);
/* 107 */     attrs.put("zimbraPrefNewMailNotificationEnabled", "TRUE");
/* 108 */     attrs.put("zimbraPrefNewMailNotificationAddress", TestUtil.getAddress(SENDER_NAME));
/* 109 */     attrs.put("zimbraNewMailNotificationSubject", NEW_MAIL_SUBJECT);
/* 110 */     attrs.put("zimbraNewMailNotificationBody", NEW_MAIL_BODY);
/* 111 */     Provisioning.getInstance().modifyAttrs(account, attrs);
/*     */     
/* 113 */     ZMailbox senderMbox = TestUtil.getZMailbox(SENDER_NAME);
/* 114 */     ZMailbox recipMbox = TestUtil.getZMailbox(RECIPIENT_NAME);
/*     */     
/*     */ 
/* 117 */     List<ZMessage> messages = TestUtil.search(recipMbox, "in:inbox subject:" + OUT_OF_OFFICE_SUBJECT);
/* 118 */     assertEquals("Messages in recipient mailbox", 0, messages.size());
/* 119 */     messages = TestUtil.search(senderMbox, "in:inbox subject:" + OUT_OF_OFFICE_SUBJECT);
/* 120 */     assertEquals("Messages in sender mailbox", 0, messages.size());
/* 121 */     messages = TestUtil.search(senderMbox, NEW_MAIL_SUBJECT);
/* 122 */     assertEquals("New mail reply", 0, messages.size());
/*     */     
/*     */ 
/* 125 */     TestUtil.sendMessage(senderMbox, RECIPIENT_NAME, OUT_OF_OFFICE_SUBJECT, "testing");
/*     */     
/*     */ 
/* 128 */     TestUtil.waitForMessage(recipMbox, "in:inbox subject:" + OUT_OF_OFFICE_SUBJECT);
/*     */     
/*     */ 
/* 131 */     TestUtil.waitForMessage(senderMbox, "in:inbox subject:" + OUT_OF_OFFICE_SUBJECT);
/* 132 */     messages = TestUtil.search(senderMbox, "in:inbox content:" + OUT_OF_OFFICE_BODY);
/* 133 */     assertEquals("Out-of-office body not found", 1, messages.size());
/*     */     
/*     */ 
/* 136 */     TestUtil.waitForMessage(senderMbox, "in:inbox subject:" + NEW_MAIL_SUBJECT);
/* 137 */     messages = TestUtil.search(senderMbox, "in:inbox content:" + NEW_MAIL_BODY);
/* 138 */     assertEquals("New mail notification body not found", 1, messages.size());
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void testOOOWhenForwardNoDelivery()
/*     */     throws Exception
/*     */   {
/* 148 */     this.isServerTest = true;
/*     */     
/* 150 */     Account account = TestUtil.getAccount(RECIPIENT_NAME);
/* 151 */     Map<String, Object> attrs = new HashMap();
/* 152 */     attrs.put("zimbraPrefOutOfOfficeReplyEnabled", "TRUE");
/* 153 */     attrs.put("zimbraPrefOutOfOfficeReply", "I am OOO");
/* 154 */     attrs.put("zimbraPrefMailForwardingAddress", "abc@xyz.com");
/* 155 */     attrs.put("zimbraPrefMailLocalDeliveryDisabled", "TRUE");
/* 156 */     Provisioning.getInstance().modifyAttrs(account, attrs);
/*     */     
/* 158 */     ZMailbox senderMbox = TestUtil.getZMailbox(SENDER_NAME);
/* 159 */     ZMailbox recipMbox = TestUtil.getZMailbox(RECIPIENT_NAME);
/*     */     
/* 161 */     String subject = NAME_PREFIX + " testOOOWhenForwardNoDelivery";
/*     */     
/*     */ 
/* 164 */     TestUtil.sendMessage(senderMbox, RECIPIENT_NAME, subject, "testing");
/*     */     
/*     */ 
/* 167 */     assertEquals(0, TestUtil.search(recipMbox, "in:inbox subject:" + subject).size());
/*     */     
/*     */ 
/* 170 */     TestUtil.waitForMessage(senderMbox, "in:inbox subject:" + subject);
/*     */   }
/*     */   
/*     */   public void tearDown() throws Exception
/*     */   {
/* 175 */     cleanUp();
/*     */     
/*     */ 
/* 178 */     Account account = TestUtil.getAccount(RECIPIENT_NAME);
/*     */     
/* 180 */     Map<String, Object> attrs = new HashMap();
/* 181 */     attrs.put("zimbraPrefOutOfOfficeReplyEnabled", LdapUtil.getLdapBooleanString(this.originalReplyEnabled));
/*     */     
/* 183 */     attrs.put("zimbraPrefOutOfOfficeReply", this.originalReply);
/* 184 */     attrs.put("zimbraPrefNewMailNotificationEnabled", LdapUtil.getLdapBooleanString(this.originalNotificationEnabled));
/*     */     
/* 186 */     attrs.put("zimbraPrefNewMailNotificationAddress", this.originalNotificationAddress);
/* 187 */     attrs.put("zimbraNewMailNotificationSubject", this.originalNotificationSubject);
/* 188 */     attrs.put("zimbraNewMailNotificationBody", this.originalNotificationBody);
/* 189 */     if ((this.originalInterceptAddresses != null) && (this.originalInterceptAddresses.length == 0)) {
/* 190 */       attrs.put("zimbraInterceptAddress", "");
/*     */     } else {
/* 192 */       attrs.put("zimbraInterceptAddress", this.originalInterceptAddresses);
/*     */     }
/* 194 */     attrs.put("zimbraInterceptSendHeadersOnly", this.originalInterceptSendHeadersOnly);
/* 195 */     attrs.put("zimbraPrefSaveToSent", this.originalSaveToSent);
/* 196 */     attrs.put("zimbraPrefMailForwardingAddress", this.originalMailForwardingAddress);
/* 197 */     attrs.put("zimbraPrefMailLocalDeliveryDisabled", LdapUtil.getLdapBooleanString(this.originalLocalDeliveryDisabled));
/*     */     
/* 199 */     Provisioning.getInstance().modifyAttrs(account, attrs);
/*     */     
/* 201 */     super.tearDown();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   private void cleanUp()
/*     */     throws Exception
/*     */   {
/* 210 */     if (this.isServerTest) {
/* 211 */       DbPool.DbConnection conn = DbPool.getConnection();
/* 212 */       Mailbox mbox = TestUtil.getMailbox(RECIPIENT_NAME);
/* 213 */       DbOutOfOffice.clear(conn, mbox);
/* 214 */       conn.commit();
/* 215 */       DbPool.quietClose(conn);
/*     */     }
/*     */     
/*     */ 
/* 219 */     for (String userName : ALL_TEST_USERS) {
/* 220 */       TestUtil.deleteTestData(userName, NAME_PREFIX);
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/server/TestNotificationServer.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */